#pragma once

#include<iostream>
#include<fstream>
#include<string>
#include"cppjieba/Jieba.hpp"
#include<boost/algorithm/string.hpp>

namespace ns_util
{
    class FileUtil
    {
    public:
        static bool ReadFile(const std::string& file_path, std::string* out)
        {
            // 以输入格式打开文件
            std::ifstream in(file_path, std::ios::in);

            if(!in.is_open())
            {
                std::cerr << "open file"  << file_path  << std::endl;
                return false;
            }

            std::string line;
            while(std::getline(in, line))
            {
                
                *out += line;
            }

            in.close();
            return true;
        }
    };

    class StringUtil
    {
    public:
        static void Split(const std::string& target, std::vector<std::string>* results, const std::string& sep)
        {
            // 使用boost库中的split函数进行切分字符串
            // 以sep作为分隔符, 多个连续的分隔符当做一个来处理!
            boost::split(*results, target, boost::is_any_of(sep), boost::token_compress_on);
        }
    };


    // 引入词库路径
    const char* const DICT_PATH = "./dict/jieba.dict.utf8";
    const char* const HMM_PATH = "./dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char* const IDF_PATH = "./dict/idf.utf8";
    const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";

    class JiebaUtil
    {
    private:
        // cppjieba::Jieba是一个类型
        static cppjieba::Jieba jieba;
    public:
        static void CutString(const std::string& src, std::vector<std::string>* out)
        {
            jieba.CutForSearch(src, *out);
        }

    };

    // 初始化
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);

}